﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using Luna小店.DTO;
using Luna小店.service;
using Luna小店.UC.门店下单.DTO;
using Luna小店.Utils;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Luna小店.UC.门店下单.form.Frm订单一览;

namespace Luna小店.model
{
	public enum Enum订单类型 { 春衫订单, 坚山订单,样衣订单,坚山美国订单,坚山美国Excel导入订单,套号订单,Luna店铺};
	/// <summary>
	/// OrderModel:定制订单实体类
	/// </summary>
	[Serializable]
	public partial class OrderModel
	{
		public OrderModel()
		{ }
		#region Model
		private int _order_id;
		private string _order_no;
		private string _order_type_cd;
		private int? _shop_id;
		private string _shop_name;
		private string _custom_order_no;
		private string _custom_name;
		private string _custom_make_shirt;
		private string _transit_group;
		private string _country;
		private int? _sleeve_flag;
		private int? _customer_id;
		private string _customer_name;
		private string _factory_id;
		private int? _style_id;
		private int? _ref_order_id;
		private string _special_order;
		private string _tryon_order;
		private int? _fit_style_size;
		private int? _tailor_id;
		private string _shipping_destination;
		private DateTime? _order_date;
		private DateTime? _payment_date;
		private DateTime? _payment_confirm_date;
		private DateTime? _order_accept_date;
		private DateTime? _order_pro_start_date;
		private DateTime? _order_pro_end_date;
		private DateTime? _order_pack_date;
		private DateTime? _order_shipments_date;
		private DateTime? _target_date;
		private DateTime? _real_date;
		private string _order_status_cd;
		private string _order_produce_status_cd;
		private string _order_qc34;
		private string _order_qc35;
		private string _order_qc36;
		private string _order_qc37;
		private decimal? _order_number;
		private decimal? _order_material_cost;
		private decimal? _order_design_cost;
		private decimal? _order_process_cost;
		private decimal? _order_pack_cost = 0.000M;
		private decimal? _order_express_cost = 0.000M;
		private decimal? _order_sell_account;
		private decimal? _order_other_cost = 0.000M;
		private string _urgent_cd;
		private string _remarks;
		private int _delete_flag = 0;
		private int _version = 1;
		private DateTime? _create_date;
		private DateTime? _update_date;
		private int? _create_user;
		private int? _update_user;
		/// <summary>
		/// auto_increment
		/// </summary>
		public int ORDER_ID
		{
			set { _order_id = value; }
			get { return _order_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_NO
		{
			set { _order_no = value; }
			get { return _order_no; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_TYPE_CD
		{
			set { _order_type_cd = value; }
			get { return _order_type_cd; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? SHOP_ID
		{
			set { _shop_id = value; }
			get { return _shop_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string SHOP_NAME
		{
			set { _shop_name = value; }
			get { return _shop_name; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string CUSTOM_ORDER_NO
		{
			set { _custom_order_no = value; }
			get { return _custom_order_no; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string CUSTOM_NAME
		{
			set { _custom_name = value; }
			get { return _custom_name; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string CUSTOM_MAKE_SHIRT
		{
			set { _custom_make_shirt = value; }
			get { return _custom_make_shirt; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string TRANSIT_GROUP
		{
			set { _transit_group = value; }
			get { return _transit_group; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string COUNTRY
		{
			set { _country = value; }
			get { return _country; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? SLEEVE_FLAG
		{
			set { _sleeve_flag = value; }
			get { return _sleeve_flag; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? CUSTOMER_ID
		{
			set { _customer_id = value; }
			get { return _customer_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string CUSTOMER_NAME
		{
			set { _customer_name = value; }
			get { return _customer_name; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string FACTORY_ID
		{
			set { _factory_id = value; }
			get { return _factory_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? STYLE_ID
		{
			set { _style_id = value; }
			get { return _style_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? REF_ORDER_ID
		{
			set { _ref_order_id = value; }
			get { return _ref_order_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string SPECIAL_ORDER
		{
			set { _special_order = value; }
			get { return _special_order; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string TRYON_ORDER
		{
			set { _tryon_order = value; }
			get { return _tryon_order; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? FIT_STYLE_SIZE
		{
			set { _fit_style_size = value; }
			get { return _fit_style_size; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? TAILOR_ID
		{
			set { _tailor_id = value; }
			get { return _tailor_id; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string SHIPPING_DESTINATION
		{
			set { _shipping_destination = value; }
			get { return _shipping_destination; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_DATE
		{
			set { _order_date = value; }
			get { return _order_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? PAYMENT_DATE
		{
			set { _payment_date = value; }
			get { return _payment_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? PAYMENT_CONFIRM_DATE
		{
			set { _payment_confirm_date = value; }
			get { return _payment_confirm_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_ACCEPT_DATE
		{
			set { _order_accept_date = value; }
			get { return _order_accept_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_PRO_START_DATE
		{
			set { _order_pro_start_date = value; }
			get { return _order_pro_start_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_PRO_END_DATE
		{
			set { _order_pro_end_date = value; }
			get { return _order_pro_end_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_PACK_DATE
		{
			set { _order_pack_date = value; }
			get { return _order_pack_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? ORDER_SHIPMENTS_DATE
		{
			set { _order_shipments_date = value; }
			get { return _order_shipments_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? TARGET_DATE
		{
			set { _target_date = value; }
			get { return _target_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? REAL_DATE
		{
			set { _real_date = value; }
			get { return _real_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_STATUS_CD
		{
			set { _order_status_cd = value; }
			get { return _order_status_cd; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_PRODUCE_STATUS_CD
		{
			set { _order_produce_status_cd = value; }
			get { return _order_produce_status_cd; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_QC34
		{
			set { _order_qc34 = value; }
			get { return _order_qc34; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_QC35
		{
			set { _order_qc35 = value; }
			get { return _order_qc35; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_QC36
		{
			set { _order_qc36 = value; }
			get { return _order_qc36; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string ORDER_QC37
		{
			set { _order_qc37 = value; }
			get { return _order_qc37; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_NUMBER
		{
			set { _order_number = value; }
			get { return _order_number; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_MATERIAL_COST
		{
			set { _order_material_cost = value; }
			get { return _order_material_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_DESIGN_COST
		{
			set { _order_design_cost = value; }
			get { return _order_design_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_PROCESS_COST
		{
			set { _order_process_cost = value; }
			get { return _order_process_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_PACK_COST
		{
			set { _order_pack_cost = value; }
			get { return _order_pack_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_EXPRESS_COST
		{
			set { _order_express_cost = value; }
			get { return _order_express_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_SELL_ACCOUNT
		{
			set { _order_sell_account = value; }
			get { return _order_sell_account; }
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDER_OTHER_COST
		{
			set { _order_other_cost = value; }
			get { return _order_other_cost; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string URGENT_CD
		{
			set { _urgent_cd = value; }
			get { return _urgent_cd; }
		}
		/// <summary>
		/// 
		/// </summary>
		public string REMARKS
		{
			set { _remarks = value; }
			get { return _remarks; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int DELETE_FLAG
		{
			set { _delete_flag = value; }
			get { return _delete_flag; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int VERSION
		{
			set { _version = value; }
			get { return _version; }
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? CREATE_DATE
		{
			set { _create_date = value; }
			get { return _create_date; }
		}
		/// <summary>
		/// on update CURRENT_TIMESTAMP
		/// </summary>
		public DateTime? UPDATE_DATE
		{
			set { _update_date = value; }
			get { return _update_date; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? CREATE_USER
		{
			set { _create_user = value; }
			get { return _create_user; }
		}
		/// <summary>
		/// 
		/// </summary>
		public int? UPDATE_USER
		{
			set { _update_user = value; }
			get { return _update_user; }
		}
		#endregion Model

	}

    public class 订单导入model {
        private String mtmOrderId;
        private String mtmStyleId;
		private Enum订单类别 @enum;
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mtmStyleId">款式ID</param>
		/// <param name="mtmOrderId">订单ID</param>
		/// <param name="OrderCount"></param>
		public 订单导入model(String mtmStyleId, String mtmOrderId, Enum订单类别 @enum) {
            this.mtmStyleId = mtmStyleId;
            this.mtmOrderId = mtmOrderId;
			this.@enum = @enum;
			//  取数据
			DTO订单同步 订单同步 =OrderService.get同步订单(mtmOrderId);
            String sql;
            if (SQLerp
                .GetDataTable("select 1 from o_order_p where ORDER_NO like '" + 订单同步.ORDER_NO + "%'")
                .Rows.Count > 0
                )
            {
                return;
            }
            else {
                this.func_订单同步(订单同步);
            }



        }

        private void func_订单同步(DTO订单同步 订单同步) {
            int OrderCount = this.getOrderCount();
			String CONTRACT_NO = "";//合同号
			DTO款式同步 款式同步 = OrderService.get同步款式(mtmStyleId);

            //  更改物料信息
            String sql = "SELECT\n" +
                "	MATERIAL_CODE,\n" +
                "	RIGHT ( MATERIAL_COMPOSITION, INSTR( MATERIAL_COMPOSITION, '-' ) -1  ) AS MATERIAL_COMPOSITION \n" +
                "FROM\n" +
                "	i_material_p \n" +
                "WHERE\n" +
                "	material_id = '" + 款式同步.SYTLE_FABRIC_ID + "'";
            DataRow dataRow = SQLmtm.GetDataRow(sql);
            款式同步.SYTLE_FABRIC_NO = dataRow["MATERIAL_CODE"].ToString();
            款式同步.STYLE_COMPOSITION = dataRow["MATERIAL_COMPOSITION"].ToString();

            款式同步.STYLE_NO = FunctionHelper.generateBillNo_ERP("s_style_p", "STYLE_NO", "SM.", "000");
            //  保存款式
            String SYS_STYLE_ID = OrderService.save同步款式(款式同步);
            List<DTODesignPoints> dto设计点 = OrderService.get同步设计点(mtmStyleId);
            OrderService.save同步设计点(dto设计点, SYS_STYLE_ID);

			List<design> designs = new List<design>();
			foreach(DTODesignPoints dto in dto设计点)
			{
				designs.Add(new design(dto));
			}

            订单同步.CUSTOM_ORDER_NO = 订单同步.ORDER_NO;
            订单同步.STYLE_ID = SYS_STYLE_ID;
            订单同步.ORDER_PRODUCE_STATUS_CD = "PRODUCTION_STATUS-PRO_00";
            订单同步.ORDER_QC34 = "QUALITY_STATUS-QC_00";
            订单同步.ORDER_QC35 = "QUALITY_STATUS-QC_00";
            订单同步.ORDER_QC36 = "QUALITY_STATUS-QC_00";
            订单同步.ORDER_QC37 = "QUALITY_STATUS-QC_00";
            订单同步.ORDER_STATUS_CD = "ORDER_STATUS-OS_20";


            if (OrderCount == 1)
            {
				//  单件同步
				CONTRACT_NO=this.func订单同步(订单同步);
            }
            else
            {
                String orderNo = 订单同步.ORDER_NO;
                //  多件同步
                for (int i = 0; i < OrderCount; i++)
                {
                    订单同步.ORDER_NO = orderNo + "-" + string.Format("{0:00}", i + 1);
					CONTRACT_NO=this.func订单同步(订单同步);
                }
            }

            DataRow 订单DataRow = this.getOrderInfo(this.mtmOrderId);
			//  barcode,水洗和运单
			//  单件同步
			string[] strArray = 订单同步.ORDER_NO.Split('-');
			String orderno = strArray[0];

			BarcodeInfoDto barcodeInfoDto = new BarcodeInfoDto(订单DataRow, this.get面料(), this.Get客户地址(orderno), 0, CONTRACT_NO, designs);
			switch (this.@enum)
			{
				case Enum订单类别.坚山订单:
					barcodeInfoDto.build坚山地址(this.mtmOrderId);
					break;
				case Enum订单类别.坚山美国订单:
					break;
			}
			sql = barcodeInfoDto.buildSQL();
            SQLerp.ExecuteSql(sql);

            if (OrderCount > 1)
            {
                //  多件同步
                for (int i = 0; i < OrderCount; i++)
                {
					//  barcode,水洗和运单
					BarcodeInfoDto barcodeInfoDto多 = new BarcodeInfoDto(订单DataRow, this.get面料(), this.Get客户地址(orderno), i + 1, CONTRACT_NO, designs);
					switch (this.@enum)
					{
						case Enum订单类别.坚山订单:
							barcodeInfoDto.build坚山地址(this.mtmOrderId);
							break;
						case Enum订单类别.坚山美国订单:
							barcodeInfoDto.build美国坚山(this.mtmOrderId);
							break;
					}
					sql = barcodeInfoDto多.buildSQL();
                    SQLerp.ExecuteSql(sql);
                }
            }
        }
		/// <summary>
		/// 返回合同号
		/// </summary>
		/// <param name="订单同步"></param>
		/// <returns></returns>
        private String func订单同步(DTO订单同步 订单同步) {
            //  保存订单
            String ORDER_ID = OrderService.save同步订单(订单同步);
			//  同步设计点

			//  保存合同
			String CONTRACT_NO = OrderService.save合同(
                Convert.ToInt32(订单同步.CUSTOMER_ID)
                , Convert.ToDateTime(订单同步.CREATE_DATE)
                , ORDER_ID
				);
			OrderService.更新同步订单状态(mtmOrderId);
			return CONTRACT_NO;

		}

        /// <summary>
        ///     取得订单数量
        /// </summary>
        /// <returns></returns>
        private int getOrderCount() {
            //  查询订单数量
            String sql = "SELECT\n" +
            "	ORDER_NUMBER \n" +
            "FROM\n" +
            "	o_order_p \n" +
            "WHERE\n" +
            "	ORDER_ID = '" + this.mtmOrderId + "';";
            try
            {
                return Convert.ToInt32(Convert.ToDouble(SQLmtm.GetDataRow(sql)["ORDER_NUMBER"].ToString()));
            }
            catch
            {
                return 1;
            }
        }


        private DataRow get面料() {
            String sql = "SELECT\n" +
                "   MATERIAL_CODE,\n" +
                "	MATERIAL_COMPOSITION\n" +
                "FROM\n" +
                "	i_material_p \n" +
                "WHERE\n" +
                "	MATERIAL_ID IN ( SELECT SYTLE_FABRIC_ID FROM s_style_p WHERE SYS_STYLE_ID = '"+this.mtmStyleId + "' )";

            return SQLmtm.GetDataRow(sql);
        }
    

        private DataRow get客户地址(String customerId) {
            String sql = "SELECT\n" +
                "	MOBILE,\n" +
                "	ADDRESS_PROVINCE_CD,\n" +
                "	ADDRESS_CITY_CD,\n" +
                "	ADDRESS_DISTRICT,\n" +
                "	ADDRESS_DETAIL,\n" +
                "	ZIP_CODE \n" +
                "FROM\n" +
                "	a_customer_address_p "+
                "WHERE\n" +
                "	CUSTOMER_ID = '"+ customerId + "'";
            return SQLmtm.GetDataRow(sql);
        }

		private DataRow Get客户地址(String ORDER_NO)
		{
			String sql = "SELECT\n" +
						"	BUSINESS_NO,\n" +
						"	BARCODE_NO,\n" +
						"	CUSTOMER_ID,\n" +
						"	ADDRESS_ID,\n" +
						"	ADDRESSEE_NAME,\n" +
						"	ADDRESSEE_TEL,\n" +
						"	ADDRESS_PROVINCE_CD,\n" +
						"	ADDRESS_CITY_CD,\n" +
						"	ADDRESS_DISTRICT,\n" +
						"	ADDRESS_DETAIL,\n" +
						"	ZIP_CODE \n" +
						"FROM\n" +
						"	f_accounting_p \n" +
						"WHERE\n" +
						"	BUSINESS_NO IN ( SELECT BUSINESS_NO FROM f_accounting_order_r WHERE ORDER_NO = '"+ ORDER_NO + "' )";
			return SQLmtm.GetDataRow(sql);
		}

		private DataRow getOrderInfo(String OrderId) {
            String sql = "SELECT\n" +
                "	s_style_p.STYLE_NAME_CN,\n" +
                "	s_style_p.STYLE_FIT_CD,\n" +
                "	s_style_p.STYLE_CATEGORY_CD,\n" +
                "	s_style_p.STYLE_SIZE_CD,\n" +
                "	s_style_p.STYLE_SIZE_GROUP_CD,\n" +
                "	o_order_p.ORDER_ID,\n" +
                "	o_order_p.OGNIZATION_ID,\n" +
                "	o_order_p.SHOP_ID,\n" +
                "	o_order_p.SHOP_NAME,\n" +
                "	o_order_p.ORDER_NO,\n" +
                "	o_order_p.ORDER_TYPE_CD,\n" +
                "	o_order_p.CUSTOM_ORDER_NO,\n" +
                "	o_order_p.CUSTOM_NAME,\n" +
                "	o_order_p.CUSTOM_MAKE_SHIRT,\n" +
                "	o_order_p.TRANSIT_GROUP,\n" +
                "	o_order_p.COUNTRY,\n" +
                "	o_order_p.SLEEVE_FLAG,\n" +
                "	o_order_p.CUSTOMER_ID,\n" +
                "	o_order_p.CUSTOMER_NAME,\n" +
                "	o_order_p.FACTORY_ID,\n" +
                "	o_order_p.STYLE_ID,\n" +
                "	o_order_p.REF_ORDER_ID,\n" +
                "	o_order_p.SPECIAL_ORDER,\n" +
                "	o_order_p.TRYON_ORDER,\n" +
                "	o_order_p.FIT_STYLE_SIZE,\n" +
                "	o_order_p.TAILOR_ID,\n" +
                "	o_order_p.SHIPPING_DESTINATION,\n" +
                "	o_order_p.PAYMENT_DATE,\n" +
                "	o_order_p.PAYMENT_CONFIRM_DATE,\n" +
                "	o_order_p.ORDER_ACCEPT_DATE,\n" +
                "	o_order_p.ORDER_PRO_START_DATE,\n" +
                "	o_order_p.ORDER_PRO_END_DATE,\n" +
                "	o_order_p.ORDER_PACK_DATE,\n" +
                "	o_order_p.ORDER_SHIPMENTS_DATE,\n" +
                "	o_order_p.TARGET_DATE,\n" +
                "	o_order_p.REAL_DATE,\n" +
                "	o_order_p.ORDER_STATUS_CD,\n" +
                "	ORDER_STATUS.ITEM_NAME_CN,\n" +
                "	o_order_p.ORDER_PRODUCE_STATUS_CD,\n" +
                "	o_order_p.ORDER_QC34,\n" +
                "	o_order_p.ORDER_QC35,\n" +
                "	o_order_p.ORDER_QC36,\n" +
                "	o_order_p.ORDER_QC37,\n" +
                "	o_order_p.ORDER_NUMBER,\n" +
                "	o_order_p.ORDER_MATERIAL_COST,\n" +
                "	o_order_p.ORDER_DESIGN_COST,\n" +
                "	o_order_p.ORDER_PROCESS_COST,\n" +
                "	o_order_p.ORDER_PACK_COST,\n" +
                "	o_order_p.ORDER_EXPRESS_COST,\n" +
                "	o_order_p.ORDER_SELL_ACCOUNT,\n" +
                "	o_order_p.ORDER_OTHER_COST,\n" +
                "	o_order_p.MATERIAL_SOURCE,\n" +
                "	o_order_p.URGENT_CD,\n" +
                "	o_order_p.AFTER_SALE_STATUS,\n" +
                "	o_order_p.FIT_COMPLETE_FLAG,\n" +
                "	o_order_p.REMARKS,\n" +
                "	o_order_p.DELETE_FLAG,\n" +
                "	o_order_p.VERSION,\n" +
                "	o_order_p.CREATE_DATE,\n" +
                "	o_order_p.UPDATE_DATE,\n" +
                "	o_order_p.CREATE_USER,\n" +
                "	o_order_p.UPDATE_USER,\n" +
                "	o_order_p.SEL_KBN,\n" +
                "	o_order_p.ACTUAL_PAYMENT_COST,\n" +
                "	o_order_p.PREFERENTIAL_AMOUNT_COST,\n" +
                "	o_order_p.PREFERENTIAL_PERCENTAGE,\n" +
                "	DATE_FORMAT( o_order_p.ORDER_DATE, '%Y-%m-%d' ) AS ORDER_DATE,\n" +
                "	print_flag.ITEM_NAME_CN AS PRINT_STATUS,\n" +
                "	fr.BUSINESS_NO,\n" +
                "	fc.CUSTOMER_NAME AS CUSTOMER_TRUE_NAME,\n" +
                "	customer.MOBILE,\n" +
                "	SUBSTRING_INDEX( s_style_p.STYLE_SIZE_CD, '-',- 1 ) AS SIZE \n" +
                "FROM\n" +
                "	o_order_p\n" +
                "	LEFT JOIN s_style_p ON o_order_p.STYLE_ID = s_style_p.SYS_STYLE_ID\n" +
                "	LEFT JOIN ( SELECT CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS ITEM_VALUE, ITEM_NAME_CN FROM a_dict_p WHERE item_cd LIKE 'ORDER_STATUS' ) ORDER_STATUS ON ORDER_STATUS.ITEM_VALUE = o_order_p.ORDER_STATUS_CD\n" +
                "	LEFT JOIN ( SELECT ITEM_NAME_CN, ITEM_VALUE FROM a_dict_p WHERE ITEM_CD = 'ORDER_PRINT_STATUS' ) print_flag ON o_order_p.PRINT_FLAG = print_flag.ITEM_VALUE\n" +
                "	LEFT JOIN f_accounting_order_r fr ON o_order_p.ORDER_ID = fr.ORDER_ID\n" +
                "	LEFT JOIN a_customer_fit_count_r fc ON fc.ID = s_style_p.CUSTOMER_COUNT_ID\n" +
                "	LEFT JOIN a_customer_p customer ON o_order_p.CUSTOMER_ID = customer.CUSTOMER_ID \n" +
                "WHERE\n" +
                "	o_order_p.ORDER_ID = '"+OrderId+"'";
            return SQLmtm.GetDataRow(sql);
        }
    }

    class BarcodeInfoDto {
        public String QR_TYPE { get; set;}
        public String QR_BAR_CODE { get; set; }
        public String QR_NAME { get; set; }
		public String QR_OTHER0 { get; set; }
		public String QR_OTHER1 { get; set; }
        public String QR_OTHER2 { get; set; }
        public String QR_OTHER4 { get; set; }
        public String QR_OTHER10 { get; set; }  //  订单号
        public String QR_OTHER11 { get; set; }  //  店名
        public String QR_OTHER12 { get; set; }
        public String QR_OTHER13 { get; set; }
        public String QR_OTHER14 { get; set; }
        public String QR_OTHER26 { get; set; }
        public String QR_OTHER27 { get; set; }
        public String QR_OTHER28 { get; set; }
        public String QR_OTHER29 { get; set; }
        public String QR_OTHER30 { get; set; }
        public String QR_OTHER31 { get; set; }
        public String QR_OTHER32 { get; set; }
        public String QR_OTHER33 { get; set; }
        public String PRINT_FLAG { get; set; }
        public String ENABLE_FLAG { get; set; }
        public String DELETE_FLAG { get; set; }
        public String REMARKS { get; set; }
        public String VERSION { get; set; }
        public String CREATE_DATE { get; set; }
        public String CREATE_USER { get; set; }
        public String UPDATE_DATE { get; set; }
        public String UPDATE_USER { get; set; }
        public BarcodeInfoDto(DataRow 订单DataRow, DataRow 面料DataRow,DataRow 客户地址DataRow,int index,String CONTRACT_NO,List<design> designs) {
            this.QR_TYPE = "5";
            if (index == 0)
            {
                //  单件
                this.QR_BAR_CODE = 订单DataRow["ORDER_NO"].ToString().Substring(订单DataRow["ORDER_NO"].ToString().Length - 6, 6); //  条码
            }
            else {
                this.QR_BAR_CODE = 订单DataRow["ORDER_NO"].ToString().Substring(订单DataRow["ORDER_NO"].ToString().Length - 6, 6)
                    + "-" + string.Format("{0:00}", index); ; //  条码
            }

            this.QR_NAME = String.IsNullOrEmpty(订单DataRow["BUSINESS_NO"].ToString())
                ? 订单DataRow["ORDER_NO"].ToString() 
                : 订单DataRow["BUSINESS_NO"].ToString(); //  订单号
            this.QR_OTHER1 = DateTime.Now.ToString();
            this.QR_OTHER2 = "ORDER_FLAG-normal_10";
            this.QR_OTHER4 = 面料DataRow["MATERIAL_CODE"].ToString();
            this.QR_OTHER10 = 订单DataRow["ORDER_NO"].ToString();
            this.QR_OTHER11 = "Luna";
            this.QR_OTHER12 = String.IsNullOrEmpty(订单DataRow["CUSTOM_NAME"].ToString())
                ? 订单DataRow["CUSTOMER_TRUE_NAME"].ToString()
                : 订单DataRow["CUSTOM_NAME"].ToString();   //  姓名
            this.QR_OTHER13 = 订单DataRow["CUSTOM_MAKE_SHIRT"].ToString();
			try
			{
				this.QR_OTHER14 = 订单DataRow["BUSINESS_NO"].ToString().Substring(订单DataRow["BUSINESS_NO"].ToString().Length - 10, 10);
			}
			catch {
				this.QR_OTHER14 = 订单DataRow["BUSINESS_NO"].ToString();
			}
			if (客户地址DataRow != null)
			{
				this.QR_OTHER26 = 客户地址DataRow["ADDRESSEE_NAME"].ToString();
				this.QR_OTHER27 = 客户地址DataRow["ADDRESSEE_TEL"].ToString();
				this.QR_OTHER28 = 客户地址DataRow["ADDRESS_PROVINCE_CD"].ToString();
				this.QR_OTHER29 = 客户地址DataRow["ADDRESS_CITY_CD"].ToString();
				this.QR_OTHER30 = 客户地址DataRow["ADDRESS_DISTRICT"].ToString();
				this.QR_OTHER31 = 客户地址DataRow["ADDRESS_DETAIL"].ToString();
				this.QR_OTHER32 = 客户地址DataRow["ZIP_CODE"].ToString();
			}
            this.QR_OTHER33 = 面料DataRow["MATERIAL_COMPOSITION"].ToString(); //  成分
            this.PRINT_FLAG = "0";
            this.ENABLE_FLAG = "1";
            this.DELETE_FLAG = "0";
            this.REMARKS = 订单DataRow["REMARKS"].ToString();
            this.VERSION = "1";
            this.CREATE_DATE = DateTime.Now.ToString();
            this.CREATE_USER = "1";
            this.UPDATE_DATE = DateTime.Now.ToString();
            this.UPDATE_USER = "1";
			this.QR_OTHER0 = CONTRACT_NO;

			Dictionary<String, List<design>> dict = new Dictionary<string, List<design>>();
			dict.Add(this.QR_BAR_CODE, designs);
			String str = RestCall.httpGetMethod(URL.接口url+"/barcode/QcItemGenerate?barcode=" + this.QR_BAR_CODE);
		}
		public BarcodeInfoDto build坚山地址(String orderid)
		{
			DataRow addr = SQLmtm.GetDataRow("SELECT\n" +
									"	`ORDER_ID`,\n" +
									"	`ADDRESS_ID`,\n" +
									"	`CONSIGNEE`,\n" +
									"	`ADDRESS_COUNTRY_CD`,\n" +
									"	`ADDRESS_PROVINCE_CD`,\n" +
									"	`ADDRESS_CITY_CD`,\n" +
									"	`ADDRESS_DISTRICT`,\n" +
									"	`ADDRESS_DETAIL`,\n" +
									"	`ZIP_CODE`,\n" +
									"	`MOBILE` \n" +
									"FROM\n" +
									"	a_kashiyama_address_p \n" +
									"WHERE\n" +
									"	ORDER_ID = '" + orderid + "'");
			this.QR_OTHER26 = addr["CONSIGNEE"].ToString();
			this.QR_OTHER27 = addr["MOBILE"].ToString();
			this.QR_OTHER28 = addr["ADDRESS_PROVINCE_CD"].ToString();
			this.QR_OTHER29 = addr["ADDRESS_CITY_CD"].ToString();
			this.QR_OTHER30 = addr["ADDRESS_DISTRICT"].ToString();
			this.QR_OTHER31 = addr["ADDRESS_DETAIL"].ToString();
			this.QR_OTHER32 = addr["ZIP_CODE"].ToString();
			this.QR_OTHER11 = "KASHIYAMA";
			return this;
		}

		public BarcodeInfoDto build美国坚山(String orderid)
		{
			DataRow dr = SQLmtm.GetDataRow("SELECT * FROM a_kashiyama_o WHERE ORDER_ID='" + orderid + "'");
			if (dr != null)
			{
				this.QR_OTHER10 = dr["KUS_ORDER_ID"].ToString();
			}
			this.QR_OTHER11 = "KASHIYAMA";
			return this;
		}
		public String buildSQL() {
            return "insert into a_bar_code_p (QR_TYPE,QR_BAR_CODE,QR_NAME,QR_OTHER1,QR_OTHER2,QR_OTHER4,QR_OTHER10,QR_OTHER11,QR_OTHER12,QR_OTHER13,QR_OTHER14,QR_OTHER26,QR_OTHER27,QR_OTHER28,QR_OTHER29,QR_OTHER30,QR_OTHER31,QR_OTHER32,QR_OTHER33,PRINT_FLAG,ENABLE_FLAG,DELETE_FLAG,REMARKS,VERSION,CREATE_DATE,CREATE_USER,UPDATE_DATE,UPDATE_USER,QR_OTHER0) "
				+ "values ('"+this.QR_TYPE+ "','"+this.QR_BAR_CODE +"'"+
                ",'" + this.QR_NAME + "'" +
                ",'" + this.QR_OTHER1 + "'" +
                ",'" + this.QR_OTHER2 + "'" +
                ",'" + this.QR_OTHER4 + "'" +
                ",'" + this.QR_OTHER10 + "'" +
                ",'" + this.QR_OTHER11 + "'" +
                ",'" + this.QR_OTHER12 + "'" +
                ",'" + this.QR_OTHER13 + "'" +
                ",'" + this.QR_OTHER14 + "'" +
                ",'" + this.QR_OTHER26 + "'" +
                ",'" + this.QR_OTHER27 + "'" +
                ",'" + this.QR_OTHER28 + "'" +
                ",'" + this.QR_OTHER29 + "'" +
                ",'" + this.QR_OTHER30 + "'" +
                ",'" + this.QR_OTHER31 + "'" +
                ",'" + this.QR_OTHER32 + "'" +
                ",'" + this.QR_OTHER33 + "'" +
                ",'" + this.PRINT_FLAG + "'" +
                ",'" + this.ENABLE_FLAG + "'" +
                ",'" + this.DELETE_FLAG + "'" +
                ",'" + this.REMARKS + "'" +
                ",'" + this.VERSION + "'" +
                ",'" + this.CREATE_DATE + "'" +
                ",'" + this.CREATE_USER + "'" +
                ",'" + this.UPDATE_DATE + "'" +
                ",'" + this.UPDATE_USER + "'"+
				",'" + this.QR_OTHER0 + "')";
        }
    }

	public class 量体图片
	{
		public Image image { get; set; }//图片
		public String PicName { get; set; }//图片名称

		public 量体图片(Image image,String picname)
		{
			this.image = image;
			this.PicName = picname;
		}
	}
	/// <summary>
	/// 质检用设计点
	/// </summary>
	public class design
	{
		public String ITEM_CD { get; set; }
		public String ITEM_VALUE { get; set; }
		public String OPTION_VALUE { get; set; }
		public design(DTODesignPoints dto)
		{
			this.ITEM_CD = dto.itemCd;
			this.ITEM_VALUE = dto.itemValue;
			this.OPTION_VALUE = dto.optionValue;
		}
	}
}
